package org.apache.flink.runtime.clusterframework.types;

import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf;
import org.apache.flink.util.AbstractID;
import org.apache.flink.util.StringUtils;

public class ConsumeItemID extends AbstractID {

    private static final long serialVersionUID = 1L;

    public ConsumeItemID() {
        super();
    }

    public ConsumeItemID(byte[] bytes) {
        super(bytes);
    }

    public ConsumeItemID(long lowerPart, long upperPart) {
        super(lowerPart, upperPart);
    }

    public static ConsumeItemID fromHexString(String hexString) {
        return new ConsumeItemID(StringUtils.hexStringToByte(hexString));
    }

    public void writeTo(ByteBuf buf) {
        buf.writeLong(lowerPart);
        buf.writeLong(upperPart);
    }

    public static ConsumeItemID fromByteBuf(ByteBuf buf) {
        final long lower = buf.readLong();
        final long upper = buf.readLong();
        return new ConsumeItemID(lower, upper);
    }
}
